package com.huiyeji.dynamic.core.bean;

import com.alibaba.fastjson.JSON;
import com.huiyeji.dynamic.core.annotations.DynamicBean;
import com.huiyeji.dynamic.core.annotations.DynamicMethod;

import java.util.List;
import java.util.Map;

@DynamicBean("json")
public class DynamicJson {

    @DynamicMethod
    public String toString(Object object){
        return JSON.toJSONString(object);
    }

    @DynamicMethod
    public Map<?,?> toMap(String json){
        return JSON.parseObject(json, Map.class);
    }

    @DynamicMethod
    public <T> List<T> toList(String json, Class<T> clazz){
        return JSON.parseArray(json, clazz);
    }
}
